﻿using ShortestPaths;
using System;
using System.IO;

namespace CMP
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = File.ReadAllLines(@"jobs.txt");
            var N = Int32.Parse(strs[0]);//任务数
            EdgeWeightedDigraph G = new EdgeWeightedDigraph(2*N+2);//2*N+2 为节点数，每个任务两个我节点，再加上起始两个节点
            int s = 2 * N, t = 2 * N + 1;//起点和终点
            for (var i = 0; i < N; i++)
            {
                string[] a = strs[i].Split(" ");
                double duration = Double.Parse(a[0]);
                G.AddEdge(new DirectedEdge(i,i+N,duration));//任务起点指向任务终点
                G.AddEdge(new DirectedEdge(s,i,0));
                G.AddEdge(new DirectedEdge(i+N,t,0));

                for (var j = 1; j < a.Length; j++)
                {
                    int successor = Int32.Parse(a[j]);
                    G.AddEdge(new DirectedEdge(i+N,successor,0));
                }
            }

            AcyclicSP lp = new AcyclicSP(G,s);
            for (var i = 0; i < N; i++)
                Console.WriteLine($"{i} distTo:"+lp.DistTo(i));
            Console.WriteLine("t distTo:" + lp.DistTo(t));
        }
    }
}
